unit IUTaxa;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons;

type
  TFormIUTaxa = class(TForm)
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    LabelCliente: TLabel;
    EditNome: TEdit;
    Label1: TLabel;
    EditValor: TEdit;
    procedure FormShow(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure EditValorExit(Sender: TObject);
    procedure EditValorKeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
    xModo:string;
    xId:integer;
  end;

var
  FormIUTaxa: TFormIUTaxa;
  sql:string;

implementation

uses Principal;

{$R *.dfm}

procedure TFormIUTaxa.FormShow(Sender: TObject);
begin
    if xModo = 'U' then
    begin
       sql := 'select * from tx_entrega where id = ' + trim(IntToStr(xId));

       FormPrincipal.QueryAux.SQL.Clear;
       FormPrincipal.QueryAux.SQL.add(sql);
       FormPrincipal.QueryAux.Close;
       FormPrincipal.QueryAux.Open;

       EditNome.Text :=  FormPrincipal.QueryAux.FieldByName('nome').AsString;
       EditValor.Text :=  FormPrincipal.QueryAux.FieldByName('valor').AsString;

       EditValor.Text := formatfloat('###,###,##0.00', StrToFloat(EditValor.Text));

    end;
end;

procedure TFormIUTaxa.BitBtn1Click(Sender: TObject);
begin
    if xModo = 'I' then
       sql := 'insert into tx_entrega (nome,valor) values (''' + EditNome.Text + ''',''' + EditValor.Text + ''')'
    else
       sql := 'update tx_entrega set nome = ''' + EditNome.Text + ''' , valor = ''' + EditValor.Text + ''' where id = ' + trim(IntToStr(xId));


    FormPrincipal.QueryAtualiza.SQL.Clear;
    FormPrincipal.QueryAtualiza.SQL.add(sql);
    FormPrincipal.QueryAtualiza.ExecSQL;

    self.Close;
end;

procedure TFormIUTaxa.EditValorExit(Sender: TObject);
begin

    if Trim(EditValor.Text) = '' then
       EditValor.Text := '0';

    EditValor.Text := formatfloat('###,###,##0.00', StrToFloat(EditValor.Text))
end;

procedure TFormIUTaxa.EditValorKeyPress(Sender: TObject; var Key: Char);
begin
if not(key in ['0'..'9','.',',',#8,#13]) then 
   key := #0;

if key in [',','.'] then 
   key := DecimalSeparator;

if key = #13 then
begin
   SelectNext(Sender as tWinControl, True, True );
   Key := #0;
end;

end;

end.
